package com.sys.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.sys.pojo.Person;
import com.sys.service.PersonService;
@Controller
@RequestMapping("/Person")
public class PersonController {

	@Autowired
	private PersonService personService;
	@RequestMapping("/selectAll")
	public String selectAllPerson(Model model) {
		List<Person> persons = personService.selectAllPerson();
		model.addAttribute("persons",persons);
		return "persons";
	}
	
	@RequestMapping("/selectone/{id}")
	public String selectPersonById(Model model,@RequestParam(value ="id") int id) {
		Person person = personService.selectPersonById(id);
		List<Person> persons=new ArrayList<>();
		persons.add(person);
		model.addAttribute("persons",persons);
		return "persons";
	}
	
	@RequestMapping("/select/{sex}")
	public String selectPersonBySex(Model model,@RequestParam(value = "sex")  char sex) {
		List<Person> persons = personService.selectPersonBySex(sex);
		model.addAttribute("persons",persons);
		return "persons";
	}
	@RequestMapping("addPerson")
	public ModelAndView addperson(Person person) {
		personService.addPerson(person);
		return null;
	}

	
	
}
